package com.example.config;

import com.example.servlet.servlet.ServletDemo1;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import java.util.Set;

/**
 * @program: sms
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-01 16:42
 **/
public class ServletInitalizer implements ServletContainerInitializer {
    @Override
    public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
        //创建servlet对象
        ServletDemo1 demo1 = new ServletDemo1();
        //上下文添加servlet,并得到servlet配置对象
        ServletRegistration.Dynamic registration = ctx.addServlet("servletDemo1", demo1);
        //注册servlet的访问映射
        registration.setLoadOnStartup(1);
        registration.addMapping("/servletDemo1");
        registration.setAsyncSupported(false);
    }
}
